﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.WXT.Domain;
using System.WXT.Domain.DTO;
using System.WXT.Infrstructre.Impl;
using System.WXT.Infrstructre.Interface;
using System.WXT.WebAPI.Application.Command.productionPickingCommand;

namespace System.WXT.WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionPickingController : ControllerBase
    {
        protected readonly IMediator mediator;

        public ProductionPickingController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 生产领料添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> productionPickingAdd(productionPickingAddCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 生产领料显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<PageDTO<productionPicking>>> productionPickingShow([FromQuery]productionPickingShowCommand command)
        {
            ApiResult<PageDTO<productionPicking>> result = new ApiResult<PageDTO<productionPicking>>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
        /// <summary>
        /// 生产原料反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<productionPicking>> productionPickingBackfill([FromQuery]productionPickingBackfillCommand command)
        {
            ApiResult<productionPicking> result = new ApiResult<productionPicking>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 生产原料删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> productionPickingDelete(productionPickingDeleteCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 生产领料审核
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> productionPickingAudit(productionPickingAuditCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 生产领料修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> productionPickingUpdate(productionPickingUpdateCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
